<template>
	<view class="sales">
		<view class="sales-card">
			<view class="card-it">
				<view class="left-name">服务类型</view>
				<view class="right-ipt">
					<input class="ipt-ipt" type="text" placeholder="请选择服务类型" placeholder-class="ipt-ipt-c">
					<image class="ipt_img" src="../../static/img/right.png" mode=""></image>
				</view>
			</view>
			<view class="card-it">
				<view class="left-name">售后原因</view>
				<view class="right-ipt">
					<input class="ipt-ipt" type="text" placeholder="请选择售后原因" placeholder-class="ipt-ipt-c">
					<image class="ipt_img" src="../../static/img/right.png" mode=""></image>
				</view>
			</view>
			<view class="card-it">
				<view class="left-name">退款金额</view>
				<view class="right-ipt">
					<input class="ipt-ipt_" v-model="refundPrice" type="text">
				</view>
			</view>
			<view class="card-it_">
				<view class="left-name">售后说明</view>
				<view class="right-ipt">
					<textarea class="textarea" placeholder="请输入退款说明" placeholder-class="ipt-ipt-c"></textarea>
				</view>
			</view>
		</view>
		<view class="upload-files">
			<view class="upload-title">
				图片上传<text class="title-text">（最多可上传6张图片）</text>
			</view>
			<u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="1" multiple
				uploadIcon="plus" uploadIconColor="#545454" :maxCount="6"></u-upload>
		</view>
		<view class="btn-p">
			<view class="pay-btn-p">
				申请售后
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				refundPrice: '100',
				fileList: [],

			};
		},
		methods: {
			// 新增图片
			async afterRead(event) {
				console.log(event);
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style lang="scss">
	.sales {
		padding-top: 20rpx;
	}

	/deep/ .u-upload__button {
		margin: 0;
		width: 245rpx !important;
		height: 166rpx !important;
		background-color: #eeeeee;
		border-radius: 5rpx;
	}

	/deep/ .u-icon__icon {
		font-size: 40rpx !important;
		font-weight: bold !important;
	}

	.sales-card {
		padding: 0 67rpx;
		background-color: #fff;
		margin-bottom: 20rpx;

		.card-it_ {
			display: flex;
			align-items: flex-start;
			justify-content: space-between;
			padding: 49rpx 0 19rpx 0;

			.left-name {
				font-size: 30rpx;
				letter-spacing: 3rpx;
				color: #333333;
			}

			.textarea {
				width: 365rpx;
				height: 165rpx;
				font-size: 26rpx;
				color: #333333;
			}
		}

		.ipt-ipt-c {
			font-size: 26rpx;
			letter-spacing: 3rpx;
			color: #989898;
		}

		.card-it {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 49rpx 0 19rpx 0;
			border-bottom: 1px solid #e5e5e5;

			.left-name {
				font-size: 30rpx;
				letter-spacing: 3rpx;
				color: #333333;
			}

			.right-ipt {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.ipt-ipt {
					font-size: 26rpx;
					color: #333333;
					margin-right: 40rpx;
				}

				.ipt-ipt_ {
					letter-spacing: 3rpx;
					color: #e72e0d;
				}

				.ipt_img {
					width: 13rpx;
					height: 24rpx;
				}
			}
		}
	}

	.upload-files {
		background-color: #fff;
		padding: 30rpx 0 50rpx 68rpx;
		box-sizing: border-box;

		.upload-title {
			font-size: 30rpx;
			letter-spacing: 3rpx;
			color: #333333;
			margin-bottom: 55rpx;

			.title-text {
				font-size: 24rpx;
				letter-spacing: 2rpx;
				color: #989898;
			}
		}
	}
	.btn-p {
		display: flex;
		align-items: center;
		justify-content: center;
	
		.pay-btn-p {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 97rpx;
			width: 713rpx;
			height: 100rpx;
			background-color: #c60122;
			border-radius: 50rpx;
			font-size: 36rpx;
			letter-spacing: 4rpx;
			color: #ffffff;
		}
	}
</style>
